package zyf;

public class Sy3 {
    public static void main(String[] args) {
        foo foo1 = new foo();
        foo foo2 = new foo();

        Thread t1 = new Thread() {
            public void run() {
                foo1.dosome();
               }

        };
        Thread t2 = new Thread() {
            public void run() {
                foo2.dosome();
            }
        };
        t1.start();
        t2.start();
    }
}

class foo{
    public static  void  dosome(){
         synchronized (foo.class) {
             try {
                 Thread t = Thread.currentThread();
                 System.out.println(t.getName() + ":正在执行dosome方法...");
                 Thread.sleep(2000);
                 System.out.println(t.getName() + ":正在执行dosome方法OK");
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
         }
    }
}

